package switchviz.core.view;


import javax.swing.BorderFactory;
import javax.swing.BoxLayout;

import switchviz.gui.component.JColorPanel;
import switchviz.gui.component.JLabeldComponent;
import switchviz.gui.component.PaddingPanel;

public class ViewConfigurationPanel extends PaddingPanel
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 116051010178120708L;
	private JLabeldComponent _txtname = null;
	private JLabeldComponent _txtdescription = null;
	private JColorPanel _clbgcolor = null;

	private ViewDataModel _datamodel = null;
	
	public ViewConfigurationPanel()
	{
		initialize();
	}
	
	public void setDataModel(ViewDataModel datamodel)
	{
		_datamodel = datamodel;
		_txtname.setText(_datamodel.getName());
		_txtdescription.setText(_datamodel.getDescription());
		_clbgcolor.setColor(_datamodel.getBGColor());
	}
	
	public ViewDataModel getDataModel()
	{
		if(_datamodel == null)
			_datamodel = new ViewDataModel();
		_datamodel.setName(_txtname.getText());
		_datamodel.setDescription(_txtdescription.getText());
		_datamodel.setBGColor(_clbgcolor.getColor());
		return _datamodel;
	}
	
	private void initialize()
	{
		_txtname = new JLabeldComponent("Name of View: ", JLabeldComponent.TEXTFIELD);
		_txtname.getTextField().setColumns(20);
		_txtdescription = new JLabeldComponent("Description: ", JLabeldComponent.TEXTAREA);
		_txtdescription.getTextArea().setRows(4);
		_clbgcolor = new JColorPanel("Background: ");
		_clbgcolor.setColor(new float[]{0.0f, 0.0f, 0.0f});
		
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		this.setBorder(BorderFactory.createLoweredBevelBorder());
		this.add(_txtname);
		this.add(_txtdescription);
		this.add(_clbgcolor);
	}

}
